<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>文件上传</title>
  <script src="https://cdn.bootcss.com/axios/0.19.2/axios.js"></script>
</head>
<body>
  <div>
    <input id="upload" type="file" accept="image/bmp,image/jpeg,image/jpg,image/png">
  </div>
  <script>
    let file = document.getElementById('upload') 

    let formData = new FormData()

    file.onchange = function (ev) {
      console.log(ev.target.files[0])
      let files = ev.target.files
      formData.append('file', files[0])

      axios.post('/upload', formData).then((resp) => {
        console.log(resp)
      })
    }
  </script>
</body>
</html>